import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useRequest } from 'vue-request'

import { textLabelTagApi } from '@/services/index'

import { MarkTaskLabelRes } from '../../components/LabelCard/types'

export const useLoadingStore = defineStore(
  'labelListStore',
  () => {
    // 实体标签
    const entityLabelList = ref<MarkTaskLabelRes[]>([])
    const { loading: entityListLoading, runAsync: runGetEntityLabelList } = useRequest(textLabelTagApi.entityList)
    const getEntityLabelList = async (params: any) => {
      const res: any = await runGetEntityLabelList({
        ...params
      })
      entityLabelList.value = res.data
    }

    // 关系标签
    const relationLabelList = ref<MarkTaskLabelRes[]>([])
    const { loading: relationListLoading, runAsync: runGetRelationLabelList } = useRequest(textLabelTagApi.relationList)
    const getRelationLabelList = async (params: any) => {
      const res: any = await runGetRelationLabelList({
        ...params
      })
      relationLabelList.value = res.data
    }

    return { entityLabelList, relationLabelList, getEntityLabelList, getRelationLabelList, entityListLoading, relationListLoading }
  },
  {
    persist: false //本地持久化存储
  }
)
